package cn.com.czpb.client.module.news;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.viewpagerindicator.TabPageIndicator;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.com.czpb.client.R;
import cn.com.czpb.client.app.BaseFragment;
import cn.com.czpb.client.custorm.CircleImageView;
import cn.com.czpb.client.model.event.ChannelSortedList;
import cn.com.czpb.client.model.event.CurrentCityEventForMainAndZiXun;
import cn.com.czpb.client.model.news.NewsBean;
import cn.com.czpb.client.model.news.NewsChannelBean;
import cn.com.czpb.client.module.MainActivity;
import cn.com.czpb.client.module.news.adapter.NewsFragmentPagerAdapter;
import cn.com.czpb.client.module.news.fragment.NewsColumnsItemFragment;
import cn.com.czpb.client.module.news.fragment.NewsHtmlFragment;
import cn.com.czpb.client.module.news.fragment.NewsItemFragment;
import cn.com.czpb.client.module.news.fragment.NewsItemFragmentMain;
import cn.com.czpb.client.module.news.fragment.ZhengWuFragment;
import cn.com.czpb.client.module.personal.WodeFragment;
import cn.com.czpb.client.module.subscribe.SubscribeFragment;
import cn.com.czpb.client.utils.LogUtils;
import cn.com.czpb.client.utils.PageCtrl;
import de.greenrobot.event.EventBus;
import de.greenrobot.event.Subscribe;


/**
 * Created by 猪猪侠 on 2017/7/3.
 */

public class ZixunFragment extends BaseFragment {

    @BindView(R.id.news_tablepage_ll)
    RelativeLayout newsTablepageLl;
    @BindView(R.id.ll_head_id)
    LinearLayout ll_head_id;
    @BindView(R.id.rl_head_id)
    RelativeLayout rl_head_id;
    @BindView(R.id.news_pager)


    ViewPager newsPager;
    @BindView(R.id.home_my)
    CircleImageView home_my;
    @BindView(R.id.home_read)
    ImageView home_read;
    Unbinder unbinder;
    @BindView(R.id.ll_search_id)
    LinearLayout llSearchId;
    @BindView(R.id.news_button)
    RelativeLayout newsButton;
    @BindView(R.id.tv_local_id)
    TextView tvLocalId;

//    @BindView(R.id.ll_bottom_id)
//    LinearLayout ll_bottom_id;
//
//    @BindView(R.id.img_play_id)
//    ImageView img_play_id;
//    @BindView(R.id.tv_title_id)
//    TextView tvTitleId;
//    @BindView(R.id.tv_double_id)
//    TextView tvDoubleId;
//    @BindView(R.id.tv_time_id)
//    TextView tvTimeId;

    private static final String TAG = "ZixunFragment";
    // 语音合成对象
//    private SpeechSynthesizer mTts;
    private TextView textView;
//    // 引擎类型
//    private String mEngineType = SpeechConstant.TYPE_CLOUD;
//    //发音人
//    private int selectedNum = 0;
//    // 默认发音人
//    private String voicer = "xiaoyan";

    //    @BindView(R.id.dividerview)
//    View mydivider;
    Unbinder unbinder1;
    @BindView(R.id.news_indicator)
    TabPageIndicator indicator;

    private NewsFragmentPagerAdapter adapter;
    ImageShowBR br;
    LoginQuitBR br_login;
    public static final String ACTION_USER = "com.hzpd.cms.user";
    public static final String ACTION_QUIT = "com.hzpd.cms.quit";//退出登录;
    public static final String ACTION_QUIT_LOGIN = "com.hzpd.cms.quit.login";


    int t = 5;
    private Timer timer;
    private boolean isPlay = false;
    private boolean isFirst = true;

    int itemPosition = 0;
    private int cuttentPosition;
//    private Handler handler = new Handler() {
//        @Override
//        public void handleMessage(Message msg) {
//            if (333 == msg.what) {
//                try {
//                    tvTimeId.setText(t + "'");
//                    t--;
//                    if (t < 0) {
//                        resetTimer();
//                    }
//                    disMissDialog();
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//
//            }
//        }
//    };


                TextView tv_1;
    int currentposition;
    private MainActivity.MyOnTouchListener onTouchListener;
    private List<NewsBean> newsList;
//    private String[] items_double= new String[]{"0.8X", "1X","1.5X","2X"};
//    private String[] items_time= new String[]{"5分钟后", "15分钟后","30分钟后","不开启定时"};
    @Override
    public int setMyContentView() {
        return R.layout.fragment_news_main_new;
    }

    public static ZixunFragment newInstance() {
        ZixunFragment newsFragment = new ZixunFragment();
        return newsFragment;
    }
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e("yong", "fragment oncreate");
        br = new ImageShowBR();
        IntentFilter filter = new IntentFilter();
        filter.addAction(MainActivity.SHOW);
        filter.addAction(MainActivity.UNSHOW);
        activity.registerReceiver(br, filter);
        br_login = new LoginQuitBR();
        IntentFilter filter1 = new IntentFilter();
        filter1.addAction(WodeFragment.ACTION_QUIT_LOGIN);
        filter1.addAction(WodeFragment.ACTION_QUIT);
        filter1.addAction(WodeFragment.ACTION_USER);
        activity.registerReceiver(br_login, filter1);
//        //语音功能
//        mTts = SpeechSynthesizer.createSynthesizer(activity,null);

    }

//    public void firstPlay(){
//
//        NewsBaseFragment frag = (NewsBaseFragment) adapter.getItem(cuttentPosition);
//        LogUtils.i("currentPositon-->"+cuttentPosition);
//        LogUtils.i("itemPosition-->"+itemPosition);
//        newsList = frag.getNewsContent();
//        if (newsList==null||newsList.size()==0){
//            return;
//        }
//        ll_bottom_id.setVisibility(View.VISIBLE);
//        isFirst = false;
//        isPlay =true;
//        LogUtils.i("newsList-->"+newsList.size());
//
//        setParam();
//        playMusic();
//
//    }
//    private void startTime() {
//        if (timer!=null){
//            timer.cancel();
//        }
//        timer=new Timer();
//        TimerTask tt=new TimerTask() {
//            @Override
//            public void run() {
//                handler.sendEmptyMessage(333);
//            }
//        };
//        timer.schedule(tt,0,5000);
//    }

//    private void resetTimer() {
//        if (null==timer){
//            return;
//        }
//        timer.cancel();
//        tvTimeId.setText("定时");
//        isFirst =true;
//        //隐藏关闭读报
//        mTts.stopSpeaking();
//        ll_bottom_id.setVisibility(View.GONE);
//    }


    @OnClick({R.id.news_button, R.id.tv_local_id, R.id.ll_search_id,R.id.home_read,R.id.img_close_id, R.id.tv_double_id, R.id.tv_time_id, R.id.img_previous_id, R.id.img_play_id, R.id.img_next_id})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.news_button:
                PageCtrl.start2EditColumnActivity(activity);
                break;
            case R.id.tv_local_id:
                PageCtrl.start2ChangeCityActivity(activity);
                break;
            case R.id.ll_search_id:
                PageCtrl.start2SearchActivity(activity);
                break;
//            case R.id.home_read:
//                if (isFirst){
//                    itemPosition = 0;
//                    firstPlay();
//                }else{
//                    if (isPlay){
//                        home_read.setImageResource(R.drawable.read1);
//                        img_play_id.setImageResource(R.drawable.start);
//                        mTts.pauseSpeaking();
//                        isPlay =false;
//                    }else {
//                        Glide.with(this).load(R.drawable.read1_gif).into(home_read);
//                        Glide.with(this).load(R.drawable.bof_gif).asGif().into(img_play_id);
//                        mTts.resumeSpeaking();
//                        isPlay =true;
//                    }
//                }
//                break;
//            case R.id.img_close_id:
//                isFirst =true;
//                //隐藏关闭读报
//                mTts.stopSpeaking();
//                ll_bottom_id.setVisibility(View.GONE);
//                home_read.setImageResource(R.drawable.read1);
//                img_play_id.setImageResource(R.drawable.start);
//                break;
//            case R.id.tv_double_id:
//                new AlertDialog.Builder(activity).
//                        setTitle("语速设置")
//                        .setItems(items_double, new DialogInterface.OnClickListener() {
//                            @Override
//                            public void onClick(DialogInterface dialogInterface, int i) {
//                                switch (i){
//                                    case 0:
//                                        tvDoubleId.setText("0.8X");
//                                        spu.setSpeed("40");
//                                        itemPosition = 0;
//                                        firstPlay();
//                                        break;
//                                    case 1:
//                                        tvDoubleId.setText("1.0X");
//                                        spu.setSpeed("50");
//                                        itemPosition = 0;
//                                        firstPlay();
//                                        break;
//                                    case 2:
//                                        tvDoubleId.setText("1.5X");
//                                        spu.setSpeed("75");
//                                        itemPosition = 0;
//                                        firstPlay();
//                                        break;
//                                    case 3:
//                                        tvDoubleId.setText("2.0X");
//                                        spu.setSpeed("100");
//                                        itemPosition = 0;
//                                        firstPlay();
//                                        break;
//                                }
//                            }
//                        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialogInterface, int i) {
//                        disMissDialog();
//                    }
//                }).setCancelable(true).show();
//                break;
//            case R.id.tv_time_id:
//                new AlertDialog.Builder(activity).
//                        setTitle("选择关闭时间")
//                        .setItems(items_time, new DialogInterface.OnClickListener() {
//                            @Override
//                            public void onClick(DialogInterface dialogInterface, int i) {
//                                switch (i){
//                                    case 0:
//                                        tvTimeId.setText("5'");
//                                        startTime();
//                                        t=5;
//                                        break;
//                                    case 1:
//                                        tvTimeId.setText("15'");
//                                        t=15;
//                                        startTime();
//                                        break;
//                                    case 2:
//                                        tvTimeId.setText("30'");
//                                        t=30;
//                                        startTime();
//                                        break;
//                                    case 3:
//                                        tvTimeId.setText("定时");
//                                        if (null==timer){
//                                            return;
//                                        }
//                                        timer.cancel();
//                                        break;
//                                }
//                            }
//                        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialogInterface, int i) {
//                        disMissDialog();
//                    }
//                }).setCancelable(true).show();
//                //开启倒计时
//                LogUtils.i("5秒倒计时");
//                break;
//            case R.id.img_previous_id:
//                //上一曲
//                if (itemPosition>0){
//                    itemPosition-=1;
//                    playMusic();
//                }else{
//                    TUtils.toast("已经是第一条新闻了");
//                }
//                LogUtils.i("上一曲");
//                break;
//            case R.id.img_play_id:
//                //播放
//
//                if (isPlay){
//                    home_read.setImageResource(R.drawable.read1);
//                    img_play_id.setImageResource(R.drawable.start);
//                    mTts.pauseSpeaking();
//                    isPlay =false;
//                }else {
//                    Glide.with(this).load(R.drawable.read1_gif).into(home_read);
//                    Glide.with(this).load(R.drawable.bof_gif).asGif().into(img_play_id);
//                    mTts.resumeSpeaking();
//                    isPlay =true;
//                }
//                break;
//            case R.id.img_next_id:
//                //下一曲
//
//                if (itemPosition<(newsList.size()-1)){
//                    itemPosition+=1;
//                    playMusic();
//                }else{
//                    TUtils.toast("已经是最后一条新闻了");
//                }
//                LogUtils.i("下一曲");
//                break;
        }
    }

//    public  void playMusic(){
//        String text = newsList.get(itemPosition).getContent();
//        if (  StringUtils.isEmpty(text) ){
//            itemPosition+=1;
//            playMusic();
//            return;
//        }
//        String title = newsList.get(itemPosition).getTitle();
//        tvTitleId.setText(title);
//        mTts.startSpeaking(text,mTtsListener);
//        Glide.with(this).load(R.drawable.read1_gif).into(home_read);
//        Glide.with(this).load(R.drawable.bof_gif).asGif().into(img_play_id);
//    }




    @OnClick(R.id.home_my)
    public void Start2HomeMy() {
//        ((MainActivity)getActivity()).addEditChannelFragment();
        PageCtrl.start2HomeMyActivity(activity);
    }
    private float mPosX;
    private float mPosY;
    private float mCurPosX;
    private float mCurPosY;
    @Override
    public void initView() {
        //                gestureDetector.onTouchEvent(ev);
        onTouchListener = new MainActivity.MyOnTouchListener() {
            @Override
            public boolean onTouch(MotionEvent ev) {
//                gestureDetector.onTouchEvent(ev);
                switch (ev.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        mPosX =ev.getX();
                        mPosY =ev.getY();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        mCurPosX= ev.getX();
                        mCurPosY= ev.getY();
                        if (mCurPosY - mPosY > 0
                                && (Math.abs(mCurPosY - mPosY) > 25)) {
                            //向下滑動

                        } else if (mCurPosY - mPosY < 0
                                && (Math.abs(mCurPosY - mPosY) > 25)) {
                            //向上滑动
                            if (rl_head_id.getVisibility()==View.VISIBLE){
                                toGone();
                            }
                        }
                        break;
                    case MotionEvent.ACTION_UP:

                        break;

                }
                return false;
            }
        };
        ((MainActivity) getActivity()).registerMyOnTouchListener(onTouchListener);

        if (spu.getCurrentCountry() != null) {
            tvLocalId.setText(spu.getCurrentCountry().getChild().get(spu.getCurrentCountryPosition()).getName());
        } else {
            tvLocalId.setText(spu.getCurrentCity());
        }
        if (spu.getUser() != null) {
            Glide.with(activity).load(spu.getUser().getAvatar_path()).into(home_my);
        }
        EventBus.getDefault().register(this);
        //设置顶部状态栏字体颜色
        mImmersionBar.statusBarDarkFont(true).init();
    }

    @Override
    public void initData() {
//        switch (spu.getSpeed()){
//            case "40":
//                tvDoubleId.setText("0.8X");
//                break;
//            case "50":
//                tvDoubleId.setText("1.0X");
//                break;
//            case "75":
//                tvDoubleId.setText("1.5X");
//                break;
//            case "100":
//                tvDoubleId.setText("2.0X");
//                break;
//
//                default:
//                    tvDoubleId.setText("1.0X");
//                    break;
//        }



//        List<NewsChannelBean> mList = DataSupport.where("ischoice=?", "1").find(NewsChannelBean.class);

        List<NewsChannelBean> mList = DataSupport.where("ischoice=?","1").order("sortOrder").find(NewsChannelBean.class);

        if (null == mList) {
            mList = new ArrayList<NewsChannelBean>();
        }
        LogUtils.i("mlist_size-->" + mList.size());
        List<NewsBaseFragment> newsItemFragmentList = new ArrayList<>();
        for (int i = 0; i < mList.size(); i++) {
            NewsChannelBean ncb = mList.get(i);
            //type   栏目类型 1普通栏目 2超链 3头条主页 4一级主栏目 5跳转政务 6广西号栏目
            //头条主页
            if ("2".equals(ncb.getType())){
                NewsHtmlFragment newsHtmlFragment = NewsHtmlFragment.newInstance(i,ncb);
                newsHtmlFragment.setTitle(ncb.getCnname());
                newsItemFragmentList.add(newsHtmlFragment);
            }
             else if ("3".equals(ncb.getType())) {
                NewsItemFragmentMain suFm = NewsItemFragmentMain.newInstance(i, ncb);
                suFm.setTitle(ncb.getCnname());
                newsItemFragmentList.add(suFm);
                //二级频道的栏目
            } else if ("4".equals(ncb.getType())) {
                NewsColumnsItemFragment itemFragment = NewsColumnsItemFragment.newInstance(i,ncb);
                itemFragment.setTitle(ncb.getCnname());
                newsItemFragmentList.add(itemFragment);
                //政务页面
            }else if ("5".equals(ncb.getType())) {
                ZhengWuFragment zhengWuFragment = ZhengWuFragment.newInstance();
                zhengWuFragment.setTitle(ncb.getCnname());
                newsItemFragmentList.add(zhengWuFragment);

                //h5 页面
            }else if ("6".equals(ncb.getType())) {
                SubscribeFragment subscribeFragment = new SubscribeFragment();
                subscribeFragment.setTitle(ncb.getCnname());
                newsItemFragmentList.add(subscribeFragment);
                //h5 页面
            }

            else {//普通新闻栏目
                NewsItemFragment itemFragment = NewsItemFragment.newInstance(i, ncb);
                itemFragment.setTitle(ncb.getCnname());
                newsItemFragmentList.add(itemFragment);
            }

//            if (CODE.TID_MAIN.equals(ncb.getTid())) {
//                NewsItemFragmentMain suFm = NewsItemFragmentMain.newInstance(i, ncb);
//                suFm.setTitle(ncb.getCnname());
//                newsItemFragmentList.add(suFm);
//            } else if (CODE.TID_SUBSCRIPT.equals(ncb.getTid())) {
//                SubscribeFragment subscribeFragment = new SubscribeFragment();
//                subscribeFragment.setTitle(ncb.getCnname());
//                newsItemFragmentList.add(subscribeFragment);
//            } else {
//                NewsItemFragment itemFragment = NewsItemFragment.newInstance(i, ncb);
//                itemFragment.setTitle(ncb.getCnname());
//                newsItemFragmentList.add(itemFragment);
//            }
        }
        if (newsItemFragmentList.size() > 0) {
            newsTablepageLl.setVisibility(View.VISIBLE);
        }
        adapter = new NewsFragmentPagerAdapter(fm, activity);
        newsPager.setAdapter(adapter);
        adapter.setFragments(newsItemFragmentList);
        newsPager.setOffscreenPageLimit(adapter.getCount());

        indicator.setViewPager(newsPager);

        indicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                cuttentPosition =position;
                itemPosition = 0;
                isFirst = true;
                NewsBaseFragment frag = (NewsBaseFragment) adapter.getItem(position);
                frag.init();
                adapter.setSelectedPosition(position);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
            }
        });
    }

    @Subscribe
    public void onEventMainThread(ChannelSortedList csl) {
//        if(csl.getsize()>5){
//            indicator.setPadding(0,0,70,0);
//        }else{
//            indicator.setPadding(0,0,0,0);
//        }
        adapter.sortChannel(csl.getSaveTitleList());
        newsPager.setOffscreenPageLimit(adapter.getCount());
        indicator.notifyDataSetChanged();
    }

    @Override
    public void onDestroyView() {
        Log.e("yong", "fragment destroyview");
        super.onDestroyView();
        activity.unregisterReceiver(br_login);
        activity.unregisterReceiver(br);
        EventBus.getDefault().unregister(this);
        unbinder1.unbind();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder1 = ButterKnife.bind(this, rootView);
        return rootView;
    }

    //图片显示
    public class ImageShowBR extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(MainActivity.SHOW)) {
                adapter.notifyDataSetChanged();
            } else if (action.equals(MainActivity.UNSHOW)) {
                adapter.notifyDataSetChanged();
            }
        }
    }

    @Subscribe
    public void onEventMainThread(CurrentCityEventForMainAndZiXun event) {
        if (spu.getCurrentCountry() != null) {
            tvLocalId.setText(spu.getCurrentCountry().getChild().get(spu.getCurrentCountryPosition()).getName());
        } else {
            tvLocalId.setText(spu.getCurrentCity());
        }
    }

    //    登录广播
    public class LoginQuitBR extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(ACTION_USER)) {
                Glide.with(activity).load(spu.getUser().getAvatar_path()).into(home_my);
            } else if (action.equals(ACTION_QUIT)) {
                home_my.setImageResource(R.drawable.home_my);
                LogUtils.i("setquit");
            } else if (action.equals(ACTION_QUIT_LOGIN)) {
                home_my.setImageResource(R.drawable.home_my);
                LogUtils.i("setquitlogin");

                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        LogUtils.i("r_login_layout.callOnClick()");
                    }
                }, 500);
            }
        }
    }

    @Override
    public void onDestroy() {
        if (timer!=null){
            timer.cancel();
        }
        Log.e("yong", "fragment destroy");
        super.onDestroy();
    }


    public void toGone(){
        AnimationSet animationSet = (AnimationSet) AnimationUtils.loadAnimation(activity, R.anim.up_out);
        ll_head_id.startAnimation(animationSet);
        animationSet.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {

                rl_head_id.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

    }
    public void toVisbility(){
        AnimationSet animationSet = (AnimationSet) AnimationUtils.loadAnimation(activity, R.anim.up_in);
        ll_head_id.startAnimation(animationSet);
        rl_head_id.setVisibility(View.VISIBLE);

    }


//    //语音功能
//    /**
//     * 参数设置
//     * @return
//     */
//    private void setParam(){
//        // 清空参数
//        if (null!=mTts){
//            mTts.setParameter(SpeechConstant.PARAMS, null);
//        }else {
//            mTts = SpeechSynthesizer.createSynthesizer(activity,null);
//        }
//        // 根据合成引擎设置相应参数
//        if(mEngineType.equals(SpeechConstant.TYPE_CLOUD)) {
//            mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
//            // 设置在线合成发音人
//            mTts.setParameter(SpeechConstant.VOICE_NAME, voicer);
//            //设置合成语速
//            mTts.setParameter(SpeechConstant.SPEED, spu.getSpeed());
//            //设置合成音调
//            mTts.setParameter(SpeechConstant.PITCH, "50");
//            //设置合成音量
//            mTts.setParameter(SpeechConstant.VOLUME,  "50");
//        }
//        else {
//            mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_LOCAL);
//            // 设置本地合成发音人 voicer为空，默认通过语记界面指定发音人。
//            mTts.setParameter(SpeechConstant.VOICE_NAME, "");
//            /**
//             * TODO 本地合成不设置语速、音调、音量，默认使用语记设置
//             * 开发者如需自定义参数，请参考在线合成参数设置
//             */
//        }
//        //设置播放器音频流类型
//        mTts.setParameter(SpeechConstant.STREAM_TYPE, "3");
//        // 设置播放合成音频打断音乐播放，默认为true
//        mTts.setParameter(SpeechConstant.KEY_REQUEST_FOCUS, "true");
//
//        // 设置音频保存路径，保存音频格式支持pcm、wav，设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限
//        // 注：AUDIO_FORMAT参数语记需要更新版本才能生效
//        mTts.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");
//        mTts.setParameter(SpeechConstant.TTS_AUDIO_PATH, Environment.getExternalStorageDirectory()+"/msc/tts.wav");
//    }
//    /**
//     * 合成回调监听。
//     */
//    private SynthesizerListener mTtsListener = new SynthesizerListener() {
//
//        @Override
//        public void onSpeakBegin() {
//            Log.e(TAG, "onSpeakBegin:开始播放 ", null);
//        }
//
//        @Override
//        public void onSpeakPaused() {
//            Log.e(TAG, "onSpeakBegin:暂停播放 ", null);
////            showTip("暂停播放");
//        }
//
//        @Override
//        public void onSpeakResumed() {
//            Log.e(TAG, "onSpeakBegin:继续播放 ", null);
////            showTip("继续播放");
//        }
//
//        @Override
//        public void onBufferProgress(int percent, int beginPos, int endPos,
//                                     String info) {
//            // 合成进度
////            mPercentForBuffering = percent;
////            showTip(String.format(getString(R.string.tts_toast_format),
////                    mPercentForBuffering, mPercentForPlaying));
//        }
//
//        @Override
//        public void onSpeakProgress(int percent, int beginPos, int endPos) {
//            // 播放进度
////            mPercentForPlaying = percent;
////            showTip(String.format(getString(R.string.tts_toast_format),
////                    mPercentForBuffering, mPercentForPlaying));
//        }
//
//        @Override
//        public void onCompleted(SpeechError error) {
//            if (error == null) {
//                if (itemPosition<(newsList.size()-1)){
//                    itemPosition+=1;
//                    String title = newsList.get(itemPosition).getTitle();
//                    String text = newsList.get(itemPosition).getContent();
//                    tvTitleId.setText(title);
//                    mTts.startSpeaking(text,mTtsListener);
//                }else{
//                    TUtils.toast("已经是最后一条新闻了");
//                }
//            } else if (error != null) {
////                showTip(error.getPlainDescription(true));
//            }
//        }
//
//        @Override
//        public void onEvent(int eventType, int arg1, int arg2, Bundle obj) {
//            // 以下代码用于获取与云端的会话id，当业务出错时将会话id提供给技术支持人员，可用于查询会话日志，定位出错原因
//            // 若使用本地能力，会话id为null
//            //	if (SpeechEvent.EVENT_SESSION_ID == eventType) {
//            //		String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);
//            //		Log.d(TAG, "session id =" + sid);
//            //	}
//        }
//    };

}
